import {Ref, ref} from "vue";
import axios from "@/utils/axios";
import {message} from "ant-design-vue";

class RotaryDeviceInfo{
    deviceId: number|null = null
    diameter: number|null = null
}

export default ()=>{
    const rotaryDeviceViewInfo = ref({
        showModal:false
    })
    const rotaryDeviceInfo = <Ref<RotaryDeviceInfo>>ref(new RotaryDeviceInfo())

    /**
     * 获取旋挖钻设备详细信息
     * @param deviceId 设备id
     * @param callback 回调函数
     */
    const getRotaryDeviceInfo = (deviceId:number, callback: Function|null = null)=>{
        rotaryDeviceInfo.value = new RotaryDeviceInfo();
        axios.post("/rotary/findDeviceParameterByDeviceId",{deviceId:deviceId}).then((res:any)=>{
            if(res.success){
                Object.assign(rotaryDeviceInfo.value,res.data)
            }else{
                rotaryDeviceInfo.value.deviceId = deviceId
            }
            if(callback) callback()
        })
    }

    /**
     * 设置旋挖钻设备详细信息
     */
    const setRotaryDeviceInfo = (callback:Function|null=null)=>{
        console.log(rotaryDeviceInfo.value)
        axios.post("/rotary/saveDeviceParameterByDeviceId",rotaryDeviceInfo.value).then((res:any)=>{
            if(res.success){
                message.info("保存成功")
                if(callback) callback()
            }else{
                message.info(res.msg)
            }
        })
    }

    return {
        rotaryDeviceViewInfo,
        rotaryDeviceInfo,
        getRotaryDeviceInfo,
        setRotaryDeviceInfo
    }
}